package com.yfm;

import org.I0Itec.zkclient.ZkClient;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
@Service
public class RegistryService implements RegistryInterface {


    ZkClient zkClient = new ZkClient("localhost:2181",5000,1000);


    @Override
    public void registry(String serviceName, String serviceAddress) {

        String registryPath = "/registry";
        if(!zkClient.exists(registryPath)) {
            zkClient.createPersistent(registryPath);
        }

        String servicePath= registryPath+"/"+ serviceName;
        if(!zkClient.exists(servicePath)){
            zkClient.createPersistent(servicePath);
        }

        String addressPath = servicePath+"/address-";
        String  addressNode =   zkClient.createEphemeralSequential(addressPath,serviceAddress);
        System.out.println( "serviceAddress:  " + serviceAddress+"   address node: "+addressNode);
    }
}
